#include <stdio.h>
#include "ofc/DFraction.h"

int main(int argc, char *argv[])
{
  DFraction *fr1  = [DFraction alloc];
  DFraction *fr2  = [DFraction new  ];
  DFraction *fr3  = [DFraction new  ];
  DText     *str;

  [fr1 init :3 :4];                    // Init with fraction 3/4

  str = [fr1 toText];
  printf("Fraction1 %0d/%0d or \"%s\".\n", [fr1 numerator], [fr1 denominator], [str cstring]);
  [str free];

  [fr2 set :4 :8];                     // Set to 1/2

  str = [fr2 toText];
  printf("Fraction2 %0d/%0d or \"%s\".\n", [fr2 numerator], [fr2 denominator], [str cstring]);
  [str free];

  [fr2 mul :fr1];                      // Fraction2 = Fraction2 * Fraction1

  [fr3 sub :fr2 :fr1];                 // Fraction3 = Fraction2 - Fraction1

  str = [fr3 toText];
  printf("Fraction3 as double %f or as string \"%s\".\n", [fr3 toDouble], [str cstring]);
  [str free];

  if ([fr1 compare :fr3] == 0)
    printf("Fraction1 is equal to fraction3.\n");
  else if ([fr1 compare :fr3] < 0)
    printf("Fraction1 is smaller than fraction3.\n");
  else
    printf("Fraction1 is greater than fraction3.\n");

  [fr1 free];                          // Cleanup
  [fr2 free];
  [fr3 free];

  return 0;
}

